/**
 * Package:com.goldcitynet.service.impl;
 * Id: SceneServiceImpl.java,$v 1.3 2008/05/05 10:47:35 $yangchuan Exp 
 * Copyright(c) 2001-2005 www.afteryuan.com
 */
package com.afteryuan.engine.service.impl;

import com.afteryuan.dao.HibernateEntityDao;
import com.afteryuan.engine.model.SceneInstance;
import com.afteryuan.engine.service.SceneInstanceService;
import com.afteryuan.util.PaginationBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;

/**
 * SceneServiceImpl
 * <p/>
 * <p><a href="SceneServiceImpl.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:afteryuan@afteryuan.com">$Author: zhangpei $</a>
 * @version $Revision: 1.1.1.1 $
 */
public class SceneInstanceServiceImpl extends HibernateEntityDao<SceneInstance> implements SceneInstanceService {

    private static Log log = LogFactory.getLog(SceneInstanceServiceImpl.class);

    public List<SceneInstance> listByFrequency(Integer length) {
        String hql = "from SceneInstance si order by si.frequency desc";
        return createList(hql, new PaginationBean(length));
    }
    
    public SceneInstance getInstanceByXY(int x, int y){    	
    	String hql = "from SceneInstance where dircX=? and dircY=?";
    	List<SceneInstance> list = createList(hql, x, y);
    	if(list!=null&&list.size()!=0){
    		return list.get(0);
    	}
    	return null;
    }

//    public SceneInstance getUserDefault(PublicUser publicUser) {
//        String hql = "select s.sceneInstance from SceneFavorites s where s.user.id='" + publicUser.getId() + "' and s.defaultType=" + SceneFavorites.IS_DEFAULT_TRUE;
//        List<SceneInstance> l = createList(hql);
//        if (l != null && l.size() > 0) return l.get(0);
//        return null;
//    }
}